const { commonPost, serverUrl, logTag } = require("./Common");
const config = require('./Common');

const NoticeUpdateConfig = async () => {
    try {
        const headers = {
            "appid": config.appid,
            "appkey": config.appkey,
        };
        const res = await commonPost(serverUrl + "noticeupdateConfig", {  }, headers);

        if (res.success && res.status === 200) {
            console.log('\n' + '='.repeat(50));
            console.log(logTag + "NoticeUpdateConfig成功" );
            console.log('\n' + '='.repeat(50));

            // 等待底层资源回收，避免 libuv crash
            await new Promise(r => setTimeout(r, 100));
            return 0;
        } else {
            console.error(logTag + "NoticeUpdateConfig失败:" + res.message);
            return 1;
        }
    } catch (error) {
        console.error(logTag + "NoticeUpdateConfig失败:" + error);
        return 1;
    }
};

NoticeUpdateConfig().then((exitCode) => {
    // ✅ 设置退出码，但不立刻中断事件循环
    process.exitCode = exitCode;
}).catch((error) => {
    console.error("未处理的错误:", error);
    process.exitCode = 1;
});
